import test = ui.test.TestPageUI;
import Label = Laya.Label;
import Handler = Laya.Handler;
import Loader = Laya.Loader;

class TestUI extends ui.main.mainUI {

	private anim:Laya.Animation;

	constructor() {
		super();
		// console.log("a:" + this.splashBg.a);
		// let a: com.tangs.MyUI = this.splashBg;
		
		// this.fish111.play();
		// Laya.loader.load("anim/anim100.ani", Laya.Handler.create(this, (): void => {
			
		// }));
		// let fish = new Laya.Animation();
		// fish.loadAnimation("anim/anim100.ani");
		// fish.pos(200, 400);
		// fish.play();
		// this.addChild(fish);

		//btn是编辑器界面设定的，代码里面能直接使用，并且有代码提示
		// this.btn.on(Laya.Event.CLICK, this, this.onBtnClick);
		// this.start.on(Laya.Event.CLICK, this, this.onStart);
		// let a = this.splashBg.a;
		this.outlet1.on(Laya.Event.CLICK, this, this.onOutlet);
		this.startEffect.on("complete", this, this.onStart);
 		
		// var colorMatrix:any = [
		// 	0.3086, 0.6094, 0.0820, 0, 0,  	//R
		// 	0.3086, 0.6094, 0.0820, 0, 0, 	//G
		// 	0.3086, 0.6094, 0.0820, 0, 0,  	//B
		// 	0, 0, 0, 1, 0, 					//A
		// ];
        // //创建灰色颜色滤镜
        // var grayFilter:Laya.ColorFilter = new Laya.ColorFilter(colorMatrix);
		// var glowFilter:Laya.GlowFilter = new Laya.GlowFilter("#000000", 8, 8, 8);
		// var blurFilter:Laya.BlurFilter = new Laya.BlurFilter();
		// this.hook.filters = [grayFilter];
		// this.fish222.filters = [grayFilter, glowFilter, blurFilter];

		
		// Laya.Animation.createFrames(["fish/l_1_1.png", "fish/l_1_2.png", "fish/l_1_3.png", "fish/l_1_4.png"], "anim3333");
		// this.anim = new Laya.Animation();
		// this.anim.loadImages(["fish/l_1_1.png", "fish/l_1_2.png", "fish/l_1_3.png", "fish/l_1_4.png"], "anim3333");
		// this.anim.pos(100, 400);
		// this.anim.interval = 150;
		// this.anim.loadAtlas("res/atlas/fish/anim.atlas", Laya.Handler.create(this, (): void => {
		// 	// this.anim.play();
		// 	// this.addChild(this.anim);

		// 	// var anim:Laya.Animation = new Laya.Animation();
		// 	// anim.pos(100, 400);
		// 	// anim.interval = 200;
		// 	// anim.play(0, true, "anim100");
		// 	// this.addChild(anim);
		// }), "anim100");
		// this.addChild(this.anim);
		// // this.anim.play(0, true, "anim3333");
		// this.anim.play();
		// this.anim.on("complete", this, (): void => {
		// 	console.log("complete");
		// });

		// let str: string = "Hello Laya";
		// let offX: number = 100;
		// for (let i: number = 0; i < str.length; ++i) {
		// 	let text:Laya.Text = this.createLabel(str[i]);
		// 	text.pos(offX, 400);
		// 	let func1 = (text:Laya.Text, dt:number): void => {
		// 		text.color = "#ff0000";
		// 		Laya.Tween.to(text, {y: 100}, 500, Laya.Ease.elasticInOut, 
		// 		Laya.Handler.create(this, func2, [text, str.length * 100]), dt);
		// 	};
		// 	let func2 = (text:Laya.Text, dt:number): void => {
		// 		text.color = "#00ff00";
		// 		Laya.Tween.to(text, {y: 400}, 500, Laya.Ease.elasticInOut, 
		// 		Laya.Handler.create(this, func1, [text, str.length * 100]), dt);
		// 	};
		// 	func1(text, i * 100);
		// 	offX += text.width;
		// }
	}

	private createLabel(char:string): Laya.Text {
		var text: Laya.Text = new Laya.Text;
		text.text = char;
		text.color = "#ff0000";
		text.fontSize = 80;
		this.addChild(text);
		return text;
	}

	private onStart(): void {
		this.splashBg.visible = false;
	}

	private onOutlet(): void {
		this.hook.y = -980;
		Laya.Tween.to(this.hook, {y:-780}, 500, null, Laya.Handler.create(this, function() {
			// this.hook.y = -980;
		}));
	}

	private onBtnClick(): void {
		//手动控制组件属性
		// this.radio.selectedIndex = 1;
		// this.clip.index = 8;
		// this.tab.selectedIndex = 2;
		// this.combobox.selectedIndex = 0;
		// this.check.selected = true;
	}

	private onBtn2Click(): void {
		//通过赋值可以简单快速修改组件属性
		//赋值有两种方式：
		//简单赋值，比如：progress:0.2，就是更改progress组件的value为2
		//复杂复制，可以通知某个属性，比如：label:{color:"#ff0000",text:"Hello LayaAir"}
		// this.box.dataSource = { slider: 50, scroll: 80, progress: 0.2, input: "This is a input", label: { color: "#ff0000", text: "Hello LayaAir" } };

		// //list赋值，先获得一个数据源数组
		// var arr: Array<any> = [];
		// for (var i: number = 0; i < 100; i++) {
		// 	arr.push({ label: "item " + i, clip: i % 9 });
		// }

		// //给list赋值更改list的显示
		// this.list.array = arr;

		//还可以自定义list渲染方式，可以打开下面注释看一下效果
		//list.renderHandler = new Handler(this, onListRender);
	}

	// private onListRender(item: Laya.Box, index: number): void {
	// 	//自定义list的渲染方式
	// 	var label: Label = item.getChildByName("label") as Label;
	// 	if (index % 2) {
	// 		label.color = "#ff0000";
	// 	} else {
	// 		label.color = "#000000";
	// 	}
	// }
}

//初始化微信小游戏
Laya.MiniAdpter.init();
//程序入口
Laya.init(640, 1136, Laya.WebGL);
Laya.stage.scaleMode = "showall";
//激活资源版本控制
Laya.ResourceVersion.enable("version.json", Handler.create(null, beginLoad), Laya.ResourceVersion.FILENAME_VERSION);

function beginLoad(){
	Laya.loader.load("res/atlas/fish.atlas", Handler.create(null, onLoaded), Handler.create(null , (progress):void => {
		console.log("progress:" + progress);
	}));
}

function onLoaded(): void {
	//实例UI界面
	var testUI: TestUI = new TestUI();
	Laya.stage.addChild(testUI);
}